<template>
  <div class="classifyBox">
    <div class="navTitle" @click.stop="toCat(cat)">
      <span>{{ cat.name }}</span>
      <span class="iconfont icon-arrow-right"></span>
    </div>
    <div class="classifyContent">
      <goodsList
        :propsData="propsData"
        :goodsList="goodsList"
        v-if="propsData.params.styleType == 1"
      ></goodsList>
      <div class="navList" v-if="propsData.params.styleType == 6">
        <div
          class="navItem"
          v-for="item in cat.list"
          :key="item.id"
          @click.stop="toCat(item)"
        >
          <image :src="item.pic_url" alt="" />
          <span class="txt">{{ item.name }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import goodsList from "../goodsList/index.vue";
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    cat: {
      type: Object,
      default: () => {
        return {};
      },
    },
    dataSource: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  components: {
    goodsList,
  },
  data() {
    return {
      goodsList: [],
    };
  },
  watch: {},
  mounted() {
    if (this.propsData.params.styleType == 1) {
      this.$nextTick(() => {
        if (this.cat.id) {
          this.getGoodsList(this.cat.id);
        }
      });
    }
  },
  methods: {
    getGoodsList(id) {
      this.$allrequest.classification
        .goodsList(
          {
            cat_id: id,
            page: 1,
            limit: 10,
          },
          true
        )
        .then((res) => {
          if (res.code == 0) {
            this.goodsList = res.data.list;
            if (this.requestIndex && this.dataSource.length) {
              if (this.requestIndex == this.dataSource.length - 1) {
                this.$emit("requestEnd");
              }
            }
          }
        });
    },
    // 跳转分类页面
    toCat(e) {
      uni.navigateTo({
        url: "/other/list/list?cat_id=" + e.id,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.classifyBox {
  width: 100%;
  .navTitle {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    font-size: 28rpx;
    padding-bottom: 16rpx;
    color: #262626;
    font-family: PingFang SC;
    font-weight: 600;
    .iconfont {
      font-weight: normal;
      font-size: 22rpx;
      color: #888;
    }
  }
  .navList {
    display: flex;
    flex-wrap: wrap;
    .navItem {
      display: flex;
      flex-direction: column;
      align-items: center;
      font-size: 24rpx;
      color: #808080;
      font-family: PingFang SC;
      margin-bottom: 30rpx;
      margin-right: 32rpx;
      width: 140rpx;
      overflow: hidden;
      image {
        width: 140rpx;
        height: 140rpx;
        border-radius: 10rpx;
        margin-bottom: 14rpx;
      }
    }
    .navItem:nth-child(3n) {
      margin-right: 0;
    }

    .txt {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 100%;
    }
  }
}
</style>
